<%@page import="cn.jekun.component.core.Constants"%>
<%@page import="cn.jekun.component.base.exceptions.BusinessException"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import = "net.sf.json.JSONObject" %>
<%@ page import = "cn.jekun.component.base.utils.EncryptUtil"%>
<%@page import="cn.jekun.component.shop.service.OrderService"%>
<%@page import="cn.jekun.component.base.spring.SpringUtils"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no"/>  
<title>优惠</title>
<!-- Mobile Specific
================================================== -->
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1" />
<!-- CSS
================================================== -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/basic.js"></script>
</head>

 <%
 String startDate = (String)session.getAttribute("_red_envelopes_startDate_");//统计开始日期
 String shopId= (String)session.getAttribute("_red_envelopes_shopId_");//商店代码
 String url = request.getParameter("url"); //扫描的路径
 String userId = request.getParameter("userId"); //操作员的用户代码
 String mobile = request.getParameter("mobile"); //操作员的mobile
 String phoneNum = request.getParameter("phoneNum");//手機號碼

	//判断网页版本是否已经登录
	if((url==null || url.trim().length()==0) && !"1".equals( (String)session.getAttribute("_RED_ENVELOPERS_LOGIN_") ) ){
		 out.print("<a style='color: red;' href='login.jsp?mobile='"+(mobile==null?"":mobile)+"'>超时或未登录，点这里请重新登录。</a>");
		 return;
	}
 
      List<Map> list = new ArrayList<Map>();
      String detailSql = "select a.order_id,b.shop_name,a.evaluation_time,a.out_order_id,st.order_status_name,u.mobile,u.user_name  from erp_orders a "
                         + " join erp_shop b on (a.shop_id=b.shop_id) join rs_user u on (a.user_id=u.user_id) "
                         + " left join erp_order_status st on (a.order_status_id=st.order_status_id)"
                         + " where a.out_order_id is not null"
                         + " and a.create_time >= to_date('"+startDate+"','yyyy-mm-dd')"
                         + (shopId==null?"":" and a.shop_id='"+shopId+"'")
                         + " order by a.evaluation_time desc nulls last"; 
     OrderService orderService = SpringUtils.getBean(OrderService.BEAN_NAME); //orderService实例对象
     list = orderService.listBySql(detailSql);
 %>

<div class="header clearfix"><a href="redEnvelopes.jsp?userId=${param.userId}&mobile=${param.mobile}&phoneNum=${param.phoneNum}&url=${param.url}"> </a><span>领优惠名单</span></div>

<div class="info cont">
    <div class="top">
        <p class="textRight"><span>合计：<%=list.size() %>个</span></p>  
    </div>
    <div class="main">
        <table>
            <colgroup>
                 <col width="8%" />
                <col width="25%" />
                <col width="20%" />
                <col width="15%" />
                <col width="32" />
            </colgroup>
            <thead>
                <tr>
                    <th>No.</th>
                    <th>手机</th>
                    <th>订单尾号</th>
                    <th>领取时间</th>
                    <th>状态</th>
                </tr>
            </thead>
            <tbody>
            <%
               
               for(int i = 0,j = list.size(); i<list.size(); i++,j--){
            	   Map row = list.get(i);
            %>
                <tr <%=userId.equals((String)row.get("OUT_ORDER_ID"))?"style='color:blue;'":"" %>>
                    <td><%=j%></td>
                    <td><%=row.get("MOBILE") %></td>
                    <td><%=row.get("ORDER_ID").toString().substring(10) %></td>
                    <td>
                        <p><%=row.get("EVALUATION_TIME")==null?"":row.get("EVALUATION_TIME").toString().substring(5, 10)%></p>
                        <p><%=row.get("EVALUATION_TIME")==null?"":row.get("EVALUATION_TIME").toString().substring(11, 16)%></p>
                    </td>
                    <td><p><%=row.get("ORDER_STATUS_NAME") %></p></td>
                </tr>
               <% } %>
            </tbody>
        </table>
    </div>
    
</div>
</body>
</html>